<?php 
namespace frontend\controllers;

use Yii;
use yii\web\Controller;
use frontend\models\Company;


class CompanyController extends Controller{
	public $layout = 'my';
	public function actionIndex(){
		
		return $this->render('index');
	}
	public function actionAbout(){
		return $this->render('about');
	}
	
	public function actionContact(){
		return $this->render('contact');
	}
	//登录
	public function actionLogin(){
		$model=new Company();
		$request=Yii::$app->request;
		if($request->isPost){
			$post=$request->post('Company');
			//var_dump($post);die;
			$company = $model->find()->where(['CEmail'=>$post['CEmail'],'CPassword'=>$post['CPassword']])->one();
			//var_dump($company);die;
			if($company){
				$cookie = new \yii\web\Cookie([
		                'name' => 'qiye',
		                'expire' => time() + 3600,
		                 'httpOnly' => true,
		                 'value' => [$company['CEmail'],$company['CId']]
	             ]);
	            Yii::$app->response->getCookies()->add($cookie);
				return $this->redirect("?r=company/index");
			}else{
				return $this->redirect("?r=company/index");
			}
		}
	}
	//注册
	public function actionSigup(){
		$model = new Company();
		$request=Yii::$app->request;
		if($request->isPost){
			$post=$request->post();
			//var_dump($post);die;
			if($model->load($post)){
				$res=$model->save(false);
				//var_dump($model);die;
				$id=$model->attributes['CId'];
				$result=$model->attributes;
				if($res){
					$cookie = new \yii\web\Cookie([
		                'name' => 'qiye',
		                'expire' => time() + 3600,
		                 'httpOnly' => true,
		                 'value' => [$result['CEmail'],$result['CId']]
		             ]);
					//var_dump($cookie);die;
		            Yii::$app->response->getCookies()->add($cookie);
					return $this->redirect("?r=company/index");
				}
			}
		}
		return $this->render('index',['model'=>$model]);
	}
	//退出
	public function actionLoginout(){
		$cookie = Yii::$app->request->cookies->get('qiye');
        //移除一个Cookie对象
        Yii::$app->response->getCookies()->remove($cookie);

        return $this->redirect("?r=company/index");
	}
	//公司信息
	public function actionMonad(){
		$model = new Company();
		$request = Yii::$app->request;
		if($request->isPost){
			$post=$request->post();
			//var_dump($post);die;
			$model->CCreatTime=time();
			$res=$model->updateAll($post['Company'],['CId'=>$post['Company']['CId']]);
				
		}
		return $this->render('monad',['model'=>$model]);
	}
	

	
}

 ?>